'use strict';

/*var app = angular.module('app');*/
angular.module('app').controller('maintenanceGroupUpdateController', [ '$rootScope', '$scope', '$http', '$state','toaster','$modal','$timeout',
	function($rootScope, $scope, $http, $state,toaster,$modal,$timeout) {
       if ($state.current.name=="main.member.maintenance.groupUpdate") {
			$scope.title = "修改维修人员组";
			init();
		} else if ($state.current.name=="main.member.maintenance.groupCreate") {
			$scope.title = "新增维修人员组";
			$scope.reset = true;
		}
       validate();
       //编辑初始化页面
       function init(){
       		$scope.param = {
       			groupCode : $state.params.groupCode
       		};
       		$.ajax({
       			type:'post',
       			url:"dac/dm/DmMaintain/updateGroup",
       			dateType:'json',
       			contentType : 'application/json;charset=UTF-8',
       			data:angular.toJson($scope.param)
       		}).then(function(result){
       			console.log(result);
       		})
       }
       //新增保存
       function validate() {
            jQuery('form').validate({
                rules : {
					groupName:{
						required:true,
					}
                },
                messages : {
                    
                    groupName:{
						required:'请输入组名',
					}
                },
                submitHandler : function() {
                    $scope.submit();
                }
            });
        };
        
        //重置表单
        $scope.resetFrom = function(){
        	$scope.record = { };
        }
        
        $scope.submit = function(){
        	var m = $scope.record;
        	$.ajax({
       			type:'post',
       			url:"dac/dm/DmMaintain/updateGroup",
       			dateType:'json',
       			contentType : 'application/json;charset=UTF-8',
       			data:angular.toJson(m)
       		}).then(function(result){
       			console.log(result);
       			if(result.httpCode==200){
       				toaster.clear('*');
					toaster.pop('success', '','新增完成');
					$timeout(function() {
						$state.go('main.member.maintenance.group');
					}, 2000);
       			}else{
       				toaster.clear('*');
					toaster.pop('error', '',result.msg);
       			}
       		})
        }
       
} ]);


